//
//  GYlargeCategory.m
//  GoodLuck
//
//  Created by apple on 2018/2/28.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYlargeCategory.h"
#import "GYNetWorkTools.h"

@implementation GYlargeCategory

+ (void)loadLargeCategory:(void (^)(NSArray * _Nullable, NSError * _Nullable))finish {
    NSMutableArray *arrays = [NSMutableArray array];
    [EasyLodingView showLodingText:@"正在加载..."];
    [GYNetWorkTools requestLargeCategory:^(NSDictionary *obj) {
        NSString *code = [obj objectForKey:@"code"];
        if ([code intValue] == 200) {
            [EasyLodingView hidenLoding];
            NSDictionary *datas = [obj objectForKey:@"datas"];
            NSArray *class_list = [datas objectForKey:@"class_list"];
            for (NSDictionary *dic in class_list) {
                GYlargeCategory *lares = [[GYlargeCategory alloc] initWithDic:dic];
                [arrays addObject:lares];
            }
            
            //设置数组第一个元素默认被选中
            GYlargeCategory *large = [arrays firstObject];
            large.select = YES;
            
            //回调数据
            finish(arrays,nil);
        }else {
            [EasyTextView showText:@"加载数据出错,请重新加载!"];
            [EasyLodingView hidenLoding];
            NSLog(@"网络加载数据出错...%@",[obj objectForKey:@"msg"]);
        }
    } error:^(NSError *error) {
        [EasyTextView showText:@"加载数据出错,请重新加载!"];
        [EasyLodingView hidenLoding];
        finish(nil,error);
    }];
}

- (instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    //NSLog(@"key =====%@",key);
}
@end
